#ifndef PYTHON_SERVER_SINGLETON_H
#define PYTHON_SERVER_SINGLETON_H

namespace edm
{
    namespace common{
        
        template<class T>
        class singleton
        {
        public:
                static T& Instance()
                {
                        if(0 == m_instance)
                        {
                                m_instance = new T();
                                atexit(Destroy);
                        }
                        return *m_instance;
                }

        private:
                static void Destroy()
                {
                        if(m_instance)
                        {
                                delete m_instance;
                                m_instance = 0;
                        }
                }
                static T* volatile 		m_instance;
        };

        template<class T>
        T* volatile singleton<T>::m_instance = 0;    
    }
}


//! how to use
//! singleton<class_name>::Instance().method
//!
#endif
